<?php
require_once "ExceptionHandler.php";
require_once "services/MailUtils.php";

class NullPointerException extends Exception implements ExceptionHandler{
	
	public function __construct($message, $code=NULL){
        parent::__construct($message, $code);
    }
    
    public function __toString(){
        return "Message: " . htmlentities($this->getMessage());
    }
   
    public function getException(){
        return $this; // This will print the return from the above method __toString()
    }
    
    public static function handleException($e){
    	
    	$htmlTemplate = file_get_contents("../www/html/error.tpl");
		
		// render error message template
		echo $htmlTemplate;
		// email the error to me
		$emailBody = $e->getMessage() . "<br/>" . $e->getTraceAsString();
		$mail = new MailUtils("mattmakins+wiisocial@gmail.com", "exception@wiisocial.mattmakins.co.uk", 
			"[WiiSocial Error]: " . $e->getFile() . ": ". $e->getMessage(), $emailBody);
		$mail->send();
    }
}

set_exception_handler(array("NullPointerException", "handleException"));
?>
